#include "CircleSegment.h"



CircleSegment::CircleSegment( ) : 
	m_fRadius(0) , 
	m_tColorType(kColorTypeNone) , 
	m_tType(kSegmentTypeNormal),
	m_pPhysicObj(0)
{

}


CircleSegment::~CircleSegment( )
{
	this->removeAllChildrenWithCleanup(true);
}



void CircleSegment::initWithType( SEGMENT_TYPE type , float radius , COLOR_TYPE colorType )
{
	m_tColorType = colorType;
	m_tType = type;

	this->initWithSprite( );

	this->setRadius( radius );

	if( !m_pPhysicObj ){
		m_pPhysicObj = new PhysicObject( );
		m_pPhysicObj->initWithObject( this , kPhysicObjectTypeCircle );
		m_pPhysicObj->setActive(true);

		PhysicManager::sharedPhysicManager()->addPhysicObject( m_pPhysicObj );
	}
}



void CircleSegment::initWithSprite( )
{
	if( m_tType == kSegmentTypeNormal ){
		this->initWithSpriteFrameName( Utility::getSpriteWithColorType(m_tColorType) );
	}else{
		//Init other type
	}
}



void CircleSegment::setRadius(float radius )
{
	m_fRadius = radius;
	float ratio = m_fRadius / ( this->getContentSize().width / 2 );
	this->setScale(ratio);
}


void CircleSegment::unActive( )
{
	Circle* pCircle = (Circle*)this->getParent();
	if( pCircle ){
		pCircle->removeSegment( this );
	}
}